package com.jeewms.www.tms.ui.itemview;

import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.jeewms.www.tms.R;
import com.jeewms.www.tms.bean.bean.HomeBtnBean;
import com.jeewms.www.tms.constance.ClassHolder;
import com.jeewms.www.tms.ui.acitivity.KcTransferActivity;
import com.jeewms.www.tms.ui.acitivity.Kcqr_Activity;
import com.jeewms.www.tms.ui.acitivity.ShangjiaAcitivity;
import com.jeewms.www.tms.ui.view.CircleImageView;
import com.jeewms.www.tms.util.Logutil;
import com.jeewms.www.tms.util.StringUtil;
import com.jeewms.www.tms.util.ToastUtil;
import com.zhy.android.percent.support.PercentLinearLayout;

/**
 * Created by 13799 on 2018/6/2.
 */

public class HomeGridItemView {


    protected Activity mActivity;
    CircleImageView imgHomeitem;
    ImageView imageView;
    TextView tvHomename;
    PercentLinearLayout ll_root;
    private View mView;
    private int type;

    public HomeGridItemView(Activity act, int type) {
        this.mActivity = act;
        this.type = type;
        if (type == 0) {
            mView = LayoutInflater.from(act).inflate(R.layout.itemhome, null);
            imageView = mView.findViewById(R.id.img_homeitem);
        }else {
            mView = LayoutInflater.from(act).inflate(R.layout.itemhome_top, null);
            imgHomeitem = mView.findViewById(R.id.img_homeitem);
        }
        tvHomename = mView.findViewById(R.id.tv_homename);
        ll_root = mView.findViewById(R.id.ll_root);
    }

    public View getView() {
        return mView;
    }

    public void bindView(final HomeBtnBean bean) {
        if (bean.getImaResId() != 0) {
            if (type == 0) {
                imageView.setImageResource(bean.getImaResId());
            }else {
                imgHomeitem.setImageResource(bean.getImaResId());
            }
        }
        if (bean.getBtnName() != null)
            tvHomename.setText(bean.getBtnName());
        ll_root.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if(StringUtil.isEmpty(bean.getBtnName()))
                    return;
                if (type == 0)
                    Jump(bean.getBtnName(),bean.getType());
                else
                    ToastUtil.show(mActivity, "功能暂未开放！");
            }
        });
    }

    private void Jump(String btnName,String type) {
        if (btnName.equals(ClassHolder.KUCUNCHAXUN)) {
            Kcqr_Activity.show(mActivity);
         //   ShangjiaAcitivity.show(mActivity,btnName,type);
            Logutil.print("使用按钮库存"+btnName);
        }
//        } else if (btnName.equals(ClassHolder.MATNR)) {
//            Resum_Activity.show(mActivity);
//        }

        else if (btnName.equals(ClassHolder.YICHU)) {
             KcTransferActivity.show(mActivity);
            Logutil.print("使用按钮移出"+btnName);
       }
        else {
            ShangjiaAcitivity.show(mActivity, btnName,type);
            Logutil.print("使用按钮"+btnName);
        }
    }
}
